#######################
# This creates Figures and tables for Supplementary section 5, comparing results of question wording experiment 3
#######################

##Find mean support for use of force over confidential information
#unconditional on question wording
force.plot3<-svymean(~tci,nd)

#format line with sort order (3), mean, se supporting use of force over confidential information
line1c<-c(3,force.plot3[1],SE(force.plot3))

#find mean, se for use of force over confidential information
#conditional on question wording
line2c<-svyby(~tci,~p_over,nd,svymean)

#bind these results together
figS5<-rbind(line2c,line1c)

#calculate 95% confidence intervals
figS5$ci_lo<-(figS5$tci-(1.96*figS5$se))
figS5$ci_hi<-(figS5$tci+(1.96*figS5$se))

#plot findings
figS5plot <- ggplot(figS5, aes(x = as.factor(p_over), y=tci*100,color=as.factor(p_over),shape=as.factor(p_over)))+
  ylim(0,10)+
  geom_point(size = 2) + 
  theme_bw()+
  theme(legend.position="none")+
  theme(axis.title.x=element_blank(),axis.title.y=element_blank())+
  theme(plot.title = element_text(hjust = 0.5))+
  geom_linerange(aes(ymin = ci_lo*100, ymax = ci_hi*100))+
   scale_x_discrete(labels=c("Even if People are Hurt or Killed","No Consequences","All Respondents")) +
  ggtitle("% Weakly or Strongly Agree \nUse of force is justified to prevent the prosecution \nof Donald Trump 
        for mishandling classified documents \nby the federal government")

#show results
figS5plot

#save results - this is figure S5A
ggsave("../Supplementary Results/FigS5A.tif", width=6, height=4, units = "in",dpi=600)

#find n for each condition
s5n<-svytable(~p_over,nd)

#create vector with total n, conditional n
#add as column to existing results
figS5$n<-c(s5n[1],s5n[2],sum(s5n))
figS5$n<-signif(figS5$n,4)

#Save as table for formatting
TS5<-figS5

#convert mean,se,ci to percent
TS5$tci<-round(100*TS5$tci,3)
TS5$se<-round(100*TS5$se,3)
TS5$ci_lo<-round(100*TS5$ci_lo,3)
TS5$ci_hi<-round(100*TS5$ci_hi,3)

#add descriptive row and column names
rownames(TS5)<-c("Even if People are Hurt and Killed","No Consequences","All Respondents")
colnames(TS5)<-c("Sample","Mean Agree or Strongly Agree (%)","Standard Error (%)","95% CI Low (%)","95% CI High (%)","Observations")

#write out results to table
write.csv(TS5,"../Supplementary Results/TableS5B.csv")






